🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / data / src / androidMain / kotlin / org / meshtastic / core / data / repository / LocationRepositoryImpl.kt
Displaying Raw • Download
core/data/src/androidMain/kotlin/org/meshtastic/core/data/repository/LocationRepositoryImpl.kt bf929c20f274232e0eb8ddc19b2dc82403e99e5b (bf929c20) Text, 5.18 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.data.repository
Tff7b72import T7ee787android.Manifest.permission.ACCESS_COARSE_LOCATION
Tff7b72import T7ee787android.Manifest.permission.ACCESS_FINE_LOCATION
Tff7b72import T7ee787android.app.Application
Tff7b72import T7ee787android.location.LocationManager
Tff7b72import T7ee787android.os.Build
Tff7b72import T7ee787androidx.annotation.RequiresPermission
Tff7b72import T7ee787androidx.core.location.LocationCompat
Tff7b72import T7ee787androidx.core.location.LocationListenerCompat
Tff7b72import T7ee787androidx.core.location.LocationManagerCompat
Tff7b72import T7ee787androidx.core.location.LocationRequestCompat
Tff7b72import T7ee787androidx.core.location.altitude.AltitudeConverterCompat
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.asExecutor
Tff7b72import T7ee787kotlinx.coroutines.channels.awaitClose
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.callbackFlow
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787org.meshtastic.core.repository.Location
Tff7b72import T7ee787org.meshtastic.core.repository.LocationRepository
Tff7b72import T7ee787org.meshtastic.core.repository.PlatformAnalytics
Tf0883e@Single
Tff7b72class T56d364LocationRepositoryImplTb4b4b4(
Tff7b72private Tff7b72val Te6edf3contextTb4b4b4: Te6edf3ApplicationTb4b4b4,
Tff7b72private Tff7b72val Te6edf3locationManagerTb4b4b4: Te6edf3LazyTff7b72<Te6edf3LocationManagerTff7b72>Tb4b4b4,
Tff7b72private Tff7b72val Te6edf3analyticsTb4b4b4: Te6edf3PlatformAnalyticsTb4b4b4,
Tff7b72private Tff7b72val Te6edf3dispatchersTb4b4b4: Te6edf3CoroutineDispatchersTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3LocationRepository Tb4b4b4{
Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72private Tff7b72const Tff7b72val Te6edf3DEFAULT_INTERVAL_MS Tff7b72= T79c0ff3T79c0ff0Te6edf3_000L
Tff7b72private Tff7b72const Tff7b72val Te6edf3MIN_DISTANCE_METERS Tff7b72= T79c0ff0f
Tff7b72private Tff7b72const Tff7b72val Te6edf3API_LEVEL_31 Tff7b72= T79c0ff3T79c0ff1
Tb4b4b4}
T8b949e/** Status of whether the app is actively subscribed to location changes. */
Tff7b72private Tff7b72val Te6edf3_receivingLocationUpdatesTb4b4b4: Te6edf3MutableStateFlowTff7b72<Tffa657BooleanTff7b72> Tff7b72= Te6edf3MutableStateFlowTb4b4b4(Tff7b72falseTb4b4b4)
Tff7b72override Tff7b72val Te6edf3receivingLocationUpdatesTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657BooleanTff7b72>
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3_receivingLocationUpdates
Tf0883e@RequiresPermissionTb4b4b4(Te6edf3anyOf Tff7b72= Tff7b72[Te6edf3ACCESS_COARSE_LOCATIONTb4b4b4, Te6edf3ACCESS_FINE_LOCATIONTff7b72]Tb4b4b4)
Tff7b72private Tff7b72fun Te6edf3LocationManagerTb4b4b4.Td2a8ffrequestLocationUpdatesTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3FlowTff7b72<Te6edf3LocationTff7b72> Tff7b72= Te6edf3callbackFlow Tb4b4b4{
Tff7b72val Te6edf3locationRequest Tff7b72=
Te6edf3LocationRequestCompatTb4b4b4.Te6edf3BuilderTb4b4b4(Te6edf3DEFAULT_INTERVAL_MSTb4b4b4)
Tb4b4b4.Te6edf3setMinUpdateDistanceMetersTb4b4b4(Te6edf3MIN_DISTANCE_METERSTb4b4b4)
Tb4b4b4.Te6edf3setQualityTb4b4b4(Te6edf3LocationRequestCompatTb4b4b4.Te6edf3QUALITY_HIGH_ACCURACYTb4b4b4)
Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3locationListener Tff7b72= Te6edf3LocationListenerCompat Tb4b4b4{ Te6edf3location Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3locationTb4b4b4.Te6edf3hasAltitudeTb4b4b4(Tb4b4b4) Tff7b72&Tff7b72& Tff7b72!Te6edf3LocationCompatTb4b4b4.Te6edf3hasMslAltitudeTb4b4b4(Te6edf3locationTb4b4b4)Tb4b4b4) Tb4b4b4{
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72try Tb4b4b4{
Te6edf3AltitudeConverterCompatTb4b4b4.Te6edf3addMslAltitudeToLocationTb4b4b4(Te6edf3contextTb4b4b4, Te6edf3locationTb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffaddMslAltitudeToLocation() failedTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Te6edf3trySendTb4b4b4(Te6edf3locationTb4b4b4)
Tb4b4b4}
Tff7b72val Te6edf3providerList Tff7b72= Te6edf3buildList Tb4b4b4{
Tff7b72val Te6edf3providers Tff7b72= Te6edf3allProviders
Tff7b72if Tb4b4b4(Te6edf3BuildTb4b4b4.Te6edf3VERSIONTb4b4b4.Te6edf3SDK_INT Tff7b72>Tff7b72= Te6edf3API_LEVEL_31 Tff7b72&Tff7b72& Te6edf3LocationManagerTb4b4b4.Te6edf3FUSED_PROVIDER Tff7b72in Te6edf3providersTb4b4b4) Tb4b4b4{
Te6edf3addTb4b4b4(Te6edf3LocationManagerTb4b4b4.Te6edf3FUSED_PROVIDERTb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3LocationManagerTb4b4b4.Te6edf3GPS_PROVIDER Tff7b72in Te6edf3providersTb4b4b4) Te6edf3addTb4b4b4(Te6edf3LocationManagerTb4b4b4.Te6edf3GPS_PROVIDERTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3LocationManagerTb4b4b4.Te6edf3NETWORK_PROVIDER Tff7b72in Te6edf3providersTb4b4b4) Te6edf3addTb4b4b4(Te6edf3LocationManagerTb4b4b4.Te6edf3NETWORK_PROVIDERTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{
Ta5d6ff"Ta5d6ffStarting location updates with Tffd700$Te6edf3providerListTa5d6ff intervalMs=Tffd700$Te6edf3DEFAULT_INTERVAL_MSTa5d6ff Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffand minDistanceM=Tffd700$Te6edf3MIN_DISTANCE_METERSTa5d6ff"
Tb4b4b4}
Te6edf3_receivingLocationUpdatesTb4b4b4.Te6edf3value Tff7b72= Tff7b72true
Te6edf3analyticsTb4b4b4.Te6edf3trackTb4b4b4(Ta5d6ff"Ta5d6fflocation_startTa5d6ff"Tb4b4b4)
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72try Tb4b4b4{
Te6edf3providerListTb4b4b4.Te6edf3forEach Tb4b4b4{ Te6edf3provider Tff7b72-Tff7b72>
Te6edf3LocationManagerCompatTb4b4b4.Te6edf3requestLocationUpdatesTb4b4b4(
Tff7b72thisTf0883e@requestLocationUpdatesTb4b4b4,
Te6edf3providerTb4b4b4,
Te6edf3locationRequestTb4b4b4,
Te6edf3dispatchersTb4b4b4.Te6edf3ioTb4b4b4.Te6edf3asExecutorTb4b4b4(Tb4b4b4)Tb4b4b4,
Te6edf3locationListenerTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3closeTb4b4b4(Te6edf3eTb4b4b4)
Tb4b4b4}
Te6edf3awaitClose Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffStopping location requestsTa5d6ff" Tb4b4b4}
Te6edf3_receivingLocationUpdatesTb4b4b4.Te6edf3value Tff7b72= Tff7b72false
Te6edf3analyticsTb4b4b4.Te6edf3trackTb4b4b4(Ta5d6ff"Ta5d6fflocation_stopTa5d6ff"Tb4b4b4)
Te6edf3LocationManagerCompatTb4b4b4.Te6edf3removeUpdatesTb4b4b4(Tff7b72thisTf0883e@requestLocationUpdatesTb4b4b4, Te6edf3locationListenerTb4b4b4)
Tb4b4b4}
Tb4b4b4}
T8b949e/** Observable flow for location updates */
Tf0883e@RequiresPermissionTb4b4b4(Te6edf3anyOf Tff7b72= Tff7b72[Te6edf3ACCESS_COARSE_LOCATIONTb4b4b4, Te6edf3ACCESS_FINE_LOCATIONTff7b72]Tb4b4b4)
Tff7b72override Tff7b72fun Td2a8ffgetLocationsTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3FlowTff7b72<Te6edf3LocationTff7b72> Tff7b72= Te6edf3locationManagerTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3requestLocationUpdatesTb4b4b4(Tb4b4b4)
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.19s